package com.dyz.baseAlgorithm.searchAlgorithm;

/**
 * @author: daiyizheng
 * @date: 2021/5/13 12:44
 * @description:
 */
public class LinearSearch {
    public static void main(String[] args) {
        int arr [] = {1, 2, 3, 4, 5 };//没有顺序的数组
        int index = seqSearch(arr, -11);
        if (index == -1) {
            System.out.println("没有找到到");
        } else {
            System.out.println("找到，下标为=" + index);
        }
    }

    private static int seqSearch(int[] arr, int value) {
        //线性查找是逐一对比，发现有相同值，就返回下标
        for(int i =0; i<arr.length;i++){
            if (arr[i] == value){
                return i;
            }
        }
        return -1;
    }
}
